package cn.sjtu.syo.publisher.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author syo 2319615164@qq.com
 * @description 发送消息的控制器
 * @date 2024/9/25
 * @Copyright syo
 */
@RequestMapping("/publish")
@RestController
@RequiredArgsConstructor
public class PublisherController {

    private final RabbitTemplate rabbitTemplate;

    @GetMapping
    public void publishToWorkQueue(@RequestParam("msg") String msg) throws InterruptedException {
        String queueName = "work.queue";

        for (int i = 0; i <= 50; i++) {
            rabbitTemplate.convertAndSend(queueName, msg + i);
            Thread.sleep(20);
        }
    }
}
